package cn.kimming.service.impl;

import cn.kimming.common.pojo.Room;
import cn.kimming.common.pojo.RoomType;
import cn.kimming.common.vo.DefaultPriceVO;
import cn.kimming.mapper.RoomMapper;
import cn.kimming.mapper.RoomTypeMapper;
import cn.kimming.service.IRoomTypeService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author 刘铭轩
 * date 2021-05-23
 */
@Service
@Transactional
public class RoomTypeServiceImpl implements IRoomTypeService {
    @Autowired
    private RoomTypeMapper roomTypeMapper;
    @Autowired
    private RoomMapper roomMapper;
    @Override
    public List<RoomType> findAll() {
        return roomTypeMapper.findAll();
    }

    @Override
    public RoomType findById(Long id) {
        return roomTypeMapper.findById(id);
    }

    @Override
    public void save(RoomType bo) {
        roomTypeMapper.insertSelective(bo);
    }

    @Override
    public void update(RoomType bo) {
        roomTypeMapper.updateByPrimaryKeySelective(bo);
    }

    @Override
    public void deleteById(Long id) {
        List<Room> rooms = roomMapper.selectAllByTypeId(id);
        for (Room room : rooms) {
            room.setRoomTypeId(null);
            roomMapper.updateByPrimaryKeySelective(room);
        }
        roomTypeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<RoomType> findOptions() {
        return roomTypeMapper.findOptions();
    }

    @Override
    public List<DefaultPriceVO> listDefaultPrice() {
        return roomTypeMapper.listDefaultPrice();
    }

    @Override
    public List<JSONObject> find4RoomTypeFilter() {
        return roomTypeMapper.find4Filter();
    }
}
